home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / clang / mcomm600.zip / ZCMPLR.C < prev    next >
C/C++ Source or Header  |  1994-10-03  |  13KB  |  370 lines

  1.  
  2. /*/////////////////////////////////////////////////////////////////////
  3. //                                                                   //
  4. //                                                                   //
  5. //  ZCMPLR.C -- compiler specific functions                          //
  6. //                                                                   //
  7. //   (c) 1991, Mike Dumdei, 6 Holly Lane, Texarkana TX, 75503        //
  8. //                                                                   //
  9. //////////////////////////////////////////////////////////////////// */
  10. #ifndef __TURBOC__          /* defined by Turbo C compiler */
  11.   #ifndef __ZTC__           /* defined by Zortech C compiler */
  12.     #define __MSC__         /* assume Microsoft C if not TC or ZTC */
  13.   #endif
  14. #endif
  15.  
  16. extern long PrevHunds;
  17. extern long PrevSecs;
  18.  
  19. /*/////////////////////////////////////////////////////////////////
  20. //                                                               //
  21. //                                                               //
  22. //      Microsoft C  /  Quick C                                  //
  23. //                                                               //
  24. //                                                               //
  25. //////////////////////////////////////////////////////////////// */
  26. #ifdef __MSC__
  27.  
  28. #include <dos.h>
  29. /*/////////////////////////////////////////////////////////
  30. //  DosFindFirst -- find file (1st instance)             //
  31. //////////////////////////////////////////////////:disk:/*/
  32. int DosFindFirst(char *pathname, int atrib, struct find_t *fstruc)
  33. {
  34.     return (_dos_findfirst(pathname, atrib, fstruc));
  35. }
  36.  
  37. /*/////////////////////////////////////////////////////////
  38. //  DosFindNext -- find file (except 1st instance)       //
  39. //////////////////////////////////////////////////:disk:/*/
  40. int DosFindNext(struct find_t *fstruc)
  41. {
  42.     return (_dos_findnext(fstruc));
  43. }
  44.  
  45. /*/////////////////////////////////////////////////////////
  46. //  DosGetDiskFree -- gets free space left on disk       //
  47. //////////////////////////////////////////////////:disk:/*/
  48. long DosGetDiskFree(int drive)
  49. {
  50.     struct diskfree_t spc;
  51.     _dos_getdiskfree(drive, &spc);
  52.     return ((long)spc.avail_clusters * (long)spc.sectors_per_cluster *
  53.      (long)spc.bytes_per_sector);
  54. }
  55.  
  56. /*/////////////////////////////////////////////////////////
  57. //  DosSetFileTime -- set file date/time                 //
  58. //////////////////////////////////////////////////:disk:/*/
  59. int DosSetFileTime(int handle, unsigned date, unsigned time)
  60. {
  61.     return (_dos_setftime(handle, date, time));
  62. }
  63.  
  64. /*/////////////////////////////////////////////////////////
  65. //  DosSetFileAttr -- set file attribute                 //
  66. //////////////////////////////////////////////////:disk:/*/
  67. int DosSetFileAttr(char *path, unsigned attrib)
  68. {
  69.     return (_dos_setfileattr(path, attrib));
  70. }
  71.  
  72. /*/////////////////////////////////////////////////////////
  73. //  getHunds -- get time to 1/100 of a second            //
  74. //////////////////////////////////////////////////:time:/*/
  75. long getHunds(void)
  76. {
  77.     struct dostime_t hmsh;
  78.     long hunds;
  79.  
  80.     _dos_gettime(&hmsh);
  81.     hunds = (((((long)hmsh.hour * 60L + (long)hmsh.minute) * 60L)
  82.      + (long)hmsh.second) * 100L) + (long)hmsh.hsecond;
  83.     while (hunds < PrevHunds)
  84.         hunds += (24L * 60L * 60L * 100L);
  85.     PrevHunds = hunds;
  86.     return (hunds);
  87. }
  88.  
  89. /*/////////////////////////////////////////////////////////
  90. //  getSeconds -- get time to nearest second             //
  91. //////////////////////////////////////////////////:time:/*/
  92. long getSeconds(void)
  93. {
  94.     struct dostime_t hmsh;
  95.     long secs;
  96.  
  97.     _dos_gettime(&hmsh);
  98.     secs = (((long)hmsh.hour * 60L + (long)hmsh.minute) * 60L) +
  99.      (long)hmsh.second;
  100.     while (secs < PrevSecs)
  101.         secs += (24L * 60L * 60L);
  102.     PrevSecs = secs;
  103.     return (secs);
  104. }
  105. #endif
  106.  
  107.  
  108. /*/////////////////////////////////////////////////////////////////
  109. //                                                               //
  110. //                                                               //
  111. //      Turbo C  /  Turbo C++                                    //
  112. //                                                               //
  113. //                                                               //
  114. //////////////////////////////////////////////////////////////// */
  115. #ifdef __TURBOC__
  116.  
  117. #include <dos.h>
  118. #include <dir.h>
  119. #include <io.h>
  120.  
  121. #if __TURBOC__ >= 0x0410
  122.  #include <bios.h>
  123. #else
  124. /*/////////////////////////////////////////////////////////
  125. //  _bios_keybrd --  link to Turbo C/C++ bios key        //
  126. /////////////////////////////////////////////////////////*/
  127. int _bios_keybrd(int flag)
  128. {
  129.     return bioskey(flag);
  130. }
  131. #endif
  132.  
  133. /*/////////////////////////////////////////////////////////
  134. //  DosFindFirst -- find file (1st instance)             //
  135. //////////////////////////////////////////////////:disk:/*/
  136. int DosFindFirst(char *pathname, int atrib, struct ffblk *fstruc)
  137. {
  138.     return (findfirst(pathname, fstruc, atrib));
  139. }
  140.  
  141. /*/////////////////////////////////////////////////////////
  142. //  DosFindNext -- find file (except 1st instance)       //
  143. //////////////////////////////////////////////////:disk:/*/
  144. int DosFindNext(struct ffblk *fstruc)
  145. {
  146.     return (findnext(fstruc));
  147. }
  148.  
  149. /*/////////////////////////////////////////////////////////
  150. //  DosGetDiskFree -- gets free space left on disk       //
  151. //////////////////////////////////////////////////:disk:/*/
  152. long DosGetDiskFree(int drive)
  153. {
  154.     struct dfree spc;
  155.     getdfree(drive, &spc);
  156.     return ((long)spc.df_avail * (long)spc.df_sclus * (long)spc.df_bsec);
  157. }
  158.  
  159. /*/////////////////////////////////////////////////////////
  160. //  getHunds -- get time to 1/100 of a second            //
  161. //////////////////////////////////////////////////:time:/*/
  162. long getHunds(void)
  163. {
  164.     struct time hmsh;
  165.     long hunds;
  166.  
  167.     gettime(&hmsh);
  168.     hunds = (((((long)hmsh.ti_hour * 60L + (long)hmsh.ti_min) * 60L)
  169.      + (long)hmsh.ti_sec) * 100L) + (long)hmsh.ti_hund;
  170.     while (hunds < PrevHunds)
  171.         hunds += (24L * 60L * 60L * 100L);
  172.     PrevHunds = hunds;
  173.     return (hunds);
  174. }
  175.  
  176. /*/////////////////////////////////////////////////////////
  177. //  getSeconds -- get time to nearest second             //
  178. //////////////////////////////////////////////////:time:/*/
  179. long getSeconds(void)
  180. {
  181.     struct time hmsh;
  182.     long secs;
  183.  
  184.     gettime(&hmsh);
  185.     secs = (((long)hmsh.ti_hour * 60L + (long)hmsh.ti_min) * 60L)
  186.      + (long)hmsh.ti_sec;
  187.     while (secs < PrevSecs)
  188.         secs += (24L * 60L * 60L);
  189.     PrevSecs = secs;
  190.     return (secs);
  191. }
  192.  
  193. /*/////////////////////////////////////////////////////////
  194. //  DosSetFileTime -- set file date/time                 //
  195. //////////////////////////////////////////////////:disk:/*/
  196. int DosSetFileTime(int handle, unsigned date, unsigned time)
  197. {
  198.     unsigned long ftim = ((unsigned long)date << 16) | (unsigned long)time;
  199.     return (setftime(handle, (struct ftime *)&ftim));
  200. }
  201.  
  202. /*/////////////////////////////////////////////////////////
  203. //  DosSetFileAttr -- set file attribute                 //
  204. //                                                       //
  205. //   Older versions of TURBO C libraries (TC++ 1.00 for  //
  206. //  sure) do not have the _dos_setfileattr function so   //
  207. //  the call to it is #if'd out.  The defined version    //
  208. //  (0x0400) corresponds to BC++ 3.0 which does have the //
  209. //  _dos_setfileattr function.  Probably some versions   //
  210. //  earlier than 4.0 do too but didn't have them to find //
  211. //  out.  It is only used if an undocumented switch is   //
  212. //  enabled so you probably will never miss it.          //
  213. //////////////////////////////////////////////////:disk:/*/
  214. int DosSetFileAttr(char *path, unsigned attrib)
  215. {
  216.   #if __TURBOC__ >= 0x0400
  217.     return (_dos_setfileattr(path, attrib));
  218.   #else
  219.     return 0;
  220.   #endif
  221. }
  222. #endif
  223.  
  224.  
  225. /*/////////////////////////////////////////////////////////////////
  226. //                                                               //
  227. //                                                               //
  228. //      Zortech C  /  Zortech C++                                //
  229. //                                                               //
  230. //                                                               //
  231. //////////////////////////////////////////////////////////////// */
  232. #ifdef __ZTC__
  233.  
  234. #define MSDOS 1
  235. #include <dos.h>
  236. long timezone = 0L;
  237.  
  238. /*/////////////////////////////////////////////////////////
  239. //  DosFindFirst -- find file (1st instance)             //
  240. //////////////////////////////////////////////////:disk: */
  241. int DosFindFirst(char *pathname, int atrib, struct find_t *fstruc)
  242. {
  243.     return (_dos_findfirst(pathname, atrib, fstruc));
  244. }
  245.  
  246. /*/////////////////////////////////////////////////////////
  247. //  DosFindNext -- find file (except 1st instance)       //
  248. //////////////////////////////////////////////////:disk: */
  249. int DosFindNext(struct find_t *fstruc)
  250. {
  251.     return (_dos_findnext(fstruc));
  252. }
  253.  
  254. /*/////////////////////////////////////////////////////////
  255. //  DosGetDiskFree -- gets free space left on disk       //
  256. //////////////////////////////////////////////////:disk: */
  257. long DosGetDiskFree(int drive)
  258. {
  259.     return (dos_getdiskfreespace(drive));
  260. }
  261.  
  262. /*/////////////////////////////////////////////////////////
  263. //  DosSetFileTime -- set file date/time                 //
  264. //////////////////////////////////////////////////:disk: */
  265. int DosSetFileTime(int handle, unsigned date, unsigned time)
  266. {
  267.     return (dos_setftime(handle, date, time));
  268. }
  269.  
  270. /*/////////////////////////////////////////////////////////
  271. //  DosSetFileAttr -- set file attribute                 //
  272. //////////////////////////////////////////////////:disk: */
  273. int DosSetFileAttr(char *path, unsigned attrib)
  274. {
  275.     return (dos_setfileattr(path, attrib));
  276. }
  277.  
  278. /*/////////////////////////////////////////////////////////
  279. //  getHunds -- get time to 1/100 of a second            //
  280. //////////////////////////////////////////////////:time:/*/
  281. long getHunds(void)
  282. {
  283.     struct dostime_t hmsh;
  284.     long hunds;
  285.  
  286.     _dos_gettime(&hmsh);
  287.     hunds = (((((long)hmsh.hour * 60L + (long)hmsh.minute) * 60L)
  288.      + (long)hmsh.second) * 100L) + (long)hmsh.hsecond;
  289.     while (hunds < PrevHunds)
  290.         hunds += (24L * 60L * 60L * 100L);
  291.     PrevHunds = hunds;
  292.     return (hunds);
  293. }
  294.  
  295. /*/////////////////////////////////////////////////////////
  296. //  getSeconds -- get time to nearest second             //
  297. //////////////////////////////////////////////////:time:/*/
  298. long getSeconds(void)
  299. {
  300.     struct dostime_t hmsh;
  301.     long secs;
  302.  
  303.     _dos_gettime(&hmsh);
  304.     secs = (((long)hmsh.hour * 60L + (long)hmsh.minute) * 60L) +
  305.      (long)hmsh.second;
  306.     while (secs < PrevSecs)
  307.         secs += (24L * 60L * 60L);
  308.     PrevSecs = secs;
  309.     return (secs);
  310. }
  311. #endif
  312.  
  313.  
  314. /*/////////////////////////////////////////////////////////////////////
  315. //                                                                   //
  316. //  The following math functions were added in TXZM version 2.15 in  //
  317. //  order to solve the following problems:                           //
  318. //                                                                   //
  319. //   1.  There was a bug in TXZM.C that sometimes caused a divide    //
  320. //       by zero error during ZMODEM restarts. This code prevents    //
  321. //       division by 0.                                              //
  322. //                                                                   //
  323. //   2.  The helper functions used by various compilers differ       //
  324. //       making precompiled libraries that used long division and    //
  325. //       multiplication difficult to support.  By moving all long    //
  326. //       multiply/divide operations to a set of functions you        //
  327. //       have source code for it doesn't matter what your            //
  328. //       compiler does to perform these operations.                  //
  329. //                                                                   //
  330. //////////////////////////////////////////////////////////////////// */
  331. #ifdef __TURBOC__
  332.   #pragma warn -par
  333. #endif
  334. unsigned long divzero(unsigned long n1)
  335. {
  336. #ifdef DEBUG
  337.     extern vDisplay(int, int, char *, ...);
  338.     int *p1 = (int *)&n1;
  339.  
  340.     vDisplay(24, 40, "divide by 0 at %04X, notify Mike\r", *(p1 + 3) - 3);
  341. #endif
  342.     return (1L);
  343. }
  344. #ifdef __TURBOC__
  345.   #pragma warn +par
  346. #endif
  347.  
  348. unsigned long uldiv(unsigned long n1, unsigned long n2)
  349. {
  350.     return (n2) ? (n1 / n2) : divzero(n1);
  351. }
  352.  
  353. unsigned long ulmod(unsigned long n1, unsigned long n2)
  354. {
  355.     return (n2) ? (n1 % n2) : divzero(n1);
  356. }
  357.  
  358. unsigned long ulmul(unsigned long n1, unsigned long n2)
  359. {
  360.     return (n1 * n2);
  361. }
  362.  
  363. unsigned long ulshl(unsigned long n1, int shiftval)
  364. {
  365.     return (n1 << shiftval);
  366. }
  367.  
  368.  
  369.  
  370.